/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */

import java.util.concurrent.TimeUnit;

/**
 * <p>Project: jse2204 - T8
 * <p>Powered by webrx On 2022-09-30 16:31:08
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class T8 {
    Object a = new Object();
    Object b = new Object();

    void m1(){
        System.out.println("m1");
        synchronized (a){
            try{
                TimeUnit.SECONDS.sleep(1);
            }catch(Exception e){
                e.printStackTrace();
            }
            try{
                int i = 3 / 0;

            }catch(Exception e){
                System.out.println("error....");
            }
            synchronized (b){

            }
        }
    }

    void m2(){
        System.out.println("m2");
        synchronized (b){
            try{
                TimeUnit.SECONDS.sleep(1);
            }catch(Exception e){
                e.printStackTrace();
            }
            synchronized (a){
                System.out.println("over");
            }
        }
    }


    public static void main(String[] args) {
        T8 t = new T8();
        var a = new Thread(t::m1,"A");
        a.start();
        var b = new Thread(t::m2,"B");
        b.start();
    }
}
